package cn.xiuxius.embedded.model;

import com.fasterxml.jackson.annotation.JsonCreator;

public class ClockSourceFlashOptionType extends AbstractFlashOptionType<ClockSourceType> {
    public ClockSourceFlashOptionType(ClockSourceType value, String cmdValue, boolean isDefault) {
        super(value, cmdValue, isDefault);
    }

    public static final ClockSourceFlashOptionType DEFAULT = new ClockSourceFlashOptionType(ClockSourceType.DEFAULT, "default", true);

    @JsonCreator
    public static ClockSourceFlashOptionType from(Object val) {
        if (val instanceof String s) {
            if ("DEFAULT".equalsIgnoreCase(s)) {
                return DEFAULT;
            }
            if ("INTERNAL".equalsIgnoreCase(s)) {
                return new ClockSourceFlashOptionType(ClockSourceType.INTERNAL, ClockSourceType.INTERNAL.getValue(), false);
            }
            if ("EXTERNAL".equalsIgnoreCase(s)) {
                return new ClockSourceFlashOptionType(ClockSourceType.EXTERNAL, ClockSourceType.EXTERNAL.getValue(), true);
            }
        }
        throw new IllegalArgumentException("Unsupported Low&High Type input: " + val);
    }

    @Override
    public String getCmdValue() {
        return getValue().getValue();
    }


    @Override
    public boolean isDefault() {
        return DEFAULT.equals(this);
    }

}
